package org.com.system.util.sql;

import org.com.system.util.model.ActionValues;
import org.com.system.util.utils.ModelUtils;
import org.com.system.util.utils.StrUtils;

public class DeleteSQLGener {
	
	
	/**
     * 根据ID生成删除数据SQL
     * 如delete from table_name where title='aaa'
     * @param model
     * @return
     */
    public static String deleteSQL(String id,Class<?> model){
    	String tableName=SQLUtils.getTableName(model);
    	StringBuffer stber=new StringBuffer("DELETE FROM "+tableName+" WHERE ID='"+id+"'");
    	return StrUtils.out(stber.toString());
    }
    
    /**
     * 根据ID生成删除数据SQL
     * 如delete from table_name where title='aaa'
     * @param model
     * @return
     */
    public static String deleteSQL(Object bean,Class<?> model){
    	StringBuffer stber=new StringBuffer();
    	if(StrUtils.isNotEmpty(ModelUtils.getFieldValue("id", bean))){
    	    stber.append(deleteSQL(ModelUtils.getFieldValue("id", bean), model));
    	}
    	return stber.toString();
    }

	/**
     * 根据字段生成删除数据SQL
     * 如delete from table_name where title='aaa'
     * @param model
     * @return
     */
    public static String deleteSQL(ActionValues<String,Object> values,Class<?> model){
    	String tableName=SQLUtils.getTableName(model);
    	StringBuffer stber=new StringBuffer("DELETE FROM "+tableName);
    	SQLGener.addWhereColumnValues(stber, values, model);
    	return StrUtils.out(stber.toString());
    }
	
}
